import java.util.Arrays;

public class MyArrayList {
    public int[] arr=new int[5];
    public int usedSize;
    public int find(int x){
        for (int i = 0; i < arr.length; i++) {
            if(this.arr[i]==x){
                return i;
            }
        }
        return -1;
    }
    public void add(int x){

        if(isFull()){
            arr[this.usedSize]=x;
            this.usedSize++;
            return;
        }
        this.arr=diata();
        arr[this.usedSize]=x;
        this.usedSize++;
    }
    public void add(int pos,int x){

        if(isFull()&&islegal(pos)){

            for (int i = usedSize-1; i >=pos ; i--) {
                this.arr[i+1]=this.arr[i];
            }
            this.arr[pos]=x;
            usedSize++;
        }
        else{
            this.arr=this.diata();
            if(islegal(pos)){

                for (int i = usedSize-1; i >=pos ; i--) {
                    this.arr[i+1] = this.arr[i ];
                }
                this.arr[pos]=x;
                usedSize++;
            }
        }
    }
    public  void del(int pos){
        if(islegal(pos)){
            for (int i = pos; i < this.usedSize-1; i++) {
                arr[i]=arr[i+1];
            }
            usedSize--;
            return;
        }
    }
    public boolean islegal(int pos){
        if(pos<0||pos>usedSize){
            return false;
        }
        return true;
    }
    public boolean isFull(){
        if(this.usedSize==arr.length){
            return false;
        }
        return true;
    }
    public int[] diata(){
        return Arrays.copyOf(this.arr,arr.length*2);
    }
    public void display(){
        for (int i = 0; i <this.usedSize; i++) {
            System.out.print(this.arr[i]+" ");
        }
    }
    public int get(int pos){
        if(islegal(pos)){
            return this.arr[pos];
        }
        return -1;
    }
    public void clear(){
        this.usedSize=0;
    }


}
